Making a CI/CD Pipeline for multi-git

Let's take advantage of GitHub Actions and create a CI/CD pipeline to build multi-git and run its tests.

We'll cover the following

CI/CD pipeline for multi-git#

Let’s start with a basic pipeline that builds the binary and runs the unit tests. Note that running the end-to-end tests is a little bit challenging in the GitHub Actions environment, so we will leave it out for now.

GitHub Actions workflows are YAML files that are defined in your repo’s .github/workflows directory. I defined two workflows:

(🐙)/multi-git/
 tree .github
.github
└── workflows
    ├── on-push.yml
    └── on-tag-push.yml

1 directory, 2 files

The on-push.yml workflow is triggered every time a commit is pushed. The on-tag-push.yml workflow is called whenever a tag is pushed. Here is what it looks like on GitHub:

Go workflow

Note that the names of the workflows are Go and Create Release. The name of the workflow is specified in the YAML file. Let’s review on-push.yml. You can see the name attribute, the on trigger, the jobs section with the build job, and the various steps:

name: Go

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:

    - name: Set up Go 1.x
      uses: actions/setup-go@v2
      with:
        go-version: ^1.14
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

    - name: Get dependencies
      run: |
        go get ---./...

    - name: Build
      run: go build -v

    - name: Test
      run: go test -./pkg/...

The trigger is the push event or pull request to master:

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

The runs-on: ubuntu-latest designates the Github runner machine that will execute the job. Different jobs can run on different runners.

Each step has a name, and it can either use an existing action, such as:

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

Or, it can use custom commands that must be available on the runner:

    - name: Get dependencies
      run: |
        go get ---./...

Note that the test section only runs tests in the pkg directory:

    - name: Test
      run: go test -./pkg/...

We can check out the output of a workflow run, which is organized into jobs and steps:

Output of a workflow run
Output of a workflow run

In the next lesson, we will create GitHub releases for Multi-git.

Introduction to Self-Updating Programs and GitHub Actions

Creating GitHub Releases for Multi-git